package org.syyo.admin.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.syyo.admin.anno.CheckPermissions;
import org.syyo.admin.anno.SysLog;
import org.syyo.admin.domain.ResultVo;
import org.syyo.admin.domain.request.RoleReq;
import org.syyo.admin.service.RoleService;

/**
 * @Auther: wangzhong
 * @Date: 2019/10/8 16:55
 * @Description: 角色模块
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @SysLog("角色添加")
    @CheckPermissions("system:role:add")
    @PostMapping("/add")
    public ResultVo addRole(@RequestBody RoleReq req){
        return roleService.addRole(req);
    }

    @SysLog("角色删除")
    @CheckPermissions("system:role:del")
    @PostMapping("/del")
    public ResultVo delRole(@RequestBody RoleReq req){
        return roleService.delRole(req);
    }

    @SysLog("角色编辑")
    @CheckPermissions("system:role:edit")
    @PostMapping("/edit")
    public ResultVo editRole(@RequestBody RoleReq req){
        return roleService.editRole(req);
    }

    /**
     * 角色详情
     * @param roleId
     * @return
     */
    @CheckPermissions("system:role:index")
    @GetMapping
    public ResultVo getRole(@RequestParam("roleId") Integer roleId){
        return roleService.getRole(roleId);
    }

    /**
     * 角色列表
     * @param req
     * @return
     */
    @CheckPermissions("system:role:index")
    @GetMapping("/list")
    public ResultVo listRole(RoleReq req){
        return roleService.listRole(req);
    }

    @SysLog("角色授权")
    @CheckPermissions("system:role:auth")
    @PostMapping("/auth")
    public ResultVo auth(@RequestBody RoleReq req){
        return roleService.auth(req);
    }

}
